﻿using System;

namespace BankSystem
{
    public class Account
    {
        protected int Id;
        protected double Balance; // 据了解C#有个decimal更适合用在货币计算，但是没用过

        public int id
        {
            get
            {
                return Id;
            }
        }

        public double balance
        {
            get
            {
                return Balance;
            }
            set
            {
                Balance = value;
            }
        }

        public Account(int id , double initialBalance)
        {
            Id = id;
            Balance = initialBalance;
        }

       
        public virtual void Withdraw(double amount) { 
            if(amount > Balance)
            {
                throw new InvalidOperationException("余额不足");
            }
            Balance -= amount;
        }

        public virtual void Deposit(double amount) // 存款
        {
            Balance += amount;
        }

        public event EventHandler<BigMoneyArgs> BigMoneyFetched; // EventHandler<TEventArgs> 是一个泛型委托类型 也可以使用ppt的delegate

        protected void onBigMoneyFetched(BigMoneyArgs e)
        {
            EventHandler<BigMoneyArgs> handler = BigMoneyFetched; // 委托执行的方法 在界面将方法加入
            handler?.Invoke(this, e);//this为来源 e包含全部信息
        }
    }
}